<template>
	<view class="mainpadding">
		<view class="wenti">问题与意见</view>
		<view class="mainpadding yijianbox margin_top">
			<textarea class="textarea radius" maxlength="100" placeholder="请输入您的问题..." v-model="content"></textarea>
			<view class="zi">{{sum}}/100字</view>
		</view>
		<!-- <view class="wenti" style="margin-top: 50rpx;">联系方式</view>
		<view class="mainpadding yijianbox margin_top">
			<input class="textarea1 radius" type="number" placeholder="请输入你的联系方式">
		</view> -->
		<view class="shangchuan margin_top">请上传问题截图</view>
		<view class="flexleft margin_top jietubox">
			<view class="flexcenter wentibox" v-for="(item,index) in upImg" :key="index">
				<view class="tupianbox">
					<view class="tupian radius">
						<image class="radius" :src="item" mode=""></image>
					</view>
					<view class="xiaotubiao" @click="deleimage(index)">
						<image src="../../static/image/system/chahao.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="flexcenter wentibox" v-if="upImg.length>=4?false:true">
				<view class="beijing" @click="uploadImg">
					<view class="xiaojiahao">
						<image src="../../static/image/system/jiahao.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	
		<view class="dibu mainpadding">
			<view class="tuiku mainpadding margin_top" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				upImg:[],
				content:""
			}
		},
		computed:{
			sum(){
				return this.content.length
			}
		},
		methods: {
			uploadImg() {
				let _this = this;
				let upImgs = _this.upImg;
				let num = 4 - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, upImg) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(image_item);
				}).catch(err => {});
			},
			deleimage(i){
				this.upImg.splice(i,1)
			},
			submit(){
				if(this.content==""){
					httpRequest.toast("请输入意见反馈")
					return false
				}
				httpRequest.request('/api/feedback/feedback', 'POST', {
					content: this.content,
					images:this.upImg.join()
				}).then(resp => {
					if(resp.code==1){
						setTimeout(() => {
							uni.navigateBack({
								delta:1
							})
						}, 1000)
					}
					httpRequest.toast(resp.msg)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.dibu {
		position: fixed;
		width: 100%;
		box-sizing: border-box;
		bottom: 60rpx;
		left: 0rpx;
	}

	.tuiku {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #FFFFFF;
		box-sizing: border-box;
		text-align: center;
		background: #DCB490;
		box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(51, 51, 51, 0.0500);
		border-radius: 50rpx;
	}

	.beijing {
		display: flex;
		justify-content: center;
		align-items: center;
		background: #F6F6F6;
		box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(51, 51, 51, 0.1000);
		width: 150rpx;
		height: 150rpx;
	}

	.xiaojiahao {
		width: 31rpx;
		height: 31rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	//
	.jietubox {
		flex-wrap: wrap;
	}

	.tupianbox {
		position: relative;
	}

	.xiaotubiao {
		position: absolute;
		top: -14rpx;
		right: -2rpx;
		width: 26rpx;
		height: 26rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.tupian {
		width: 150rpx;
		height: 150rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.wentibox {
		width: 25%;
	}

	.shangchuan {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}

	.yijianbox {
		background: #F6F6F6;
		box-shadow: 0px 0px 15px 0px rgba(51, 51, 51, 0.1000);
	}

	.zi {
		text-align: right;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
	}

	.textarea {
		padding-left: 4rpx;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
		height: 150rpx;
	}
	.textarea1 {
		padding-left: 4rpx;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
	}

	.wenti {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
	}
</style>
